package com.apsd.lpr.service;

import com.apsd.lpr.PlateRecognition;
import org.bytedeco.javacpp.opencv_core;
import org.bytedeco.javacpp.opencv_imgcodecs;
import com.apsd.lpr.core.CharsRecognise;
import com.apsd.lpr.core.PlateDetect;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 大稽
 * @date2018/9/2213:57
 */
@Service
public class LprServiceImpl implements LprService {

    @Override
    public  List<String>  doLprService(String imgPath) {
        int sum=50;
        int errNum=0;
        int sumTime=0;
        long longTime=0;
        List<String> resultList = new ArrayList<>();
        for(int i=sum;i>0;i--){
            opencv_core.Mat src = opencv_imgcodecs.imread(imgPath);
            long now =System.currentTimeMillis();
            String ret= PlateRecognition.plateRecognise(src);
            resultList.add(ret);
            System.err.println(ret);
            long s=System.currentTimeMillis()-now;
            if(s>longTime){
                longTime=s;
            }
            sumTime+=s;
            if(!"川A0CP56".equals(ret)){
                errNum++;
            }
        }
        System.err.println("总数量："+sum);
        System.err.println("单次最长耗时："+longTime+"ms");

        BigDecimal errSum=new BigDecimal(errNum);
        BigDecimal sumNum=new BigDecimal(sum);
        BigDecimal c=sumNum.subtract(errSum).divide(sumNum).multiply(new BigDecimal(100));
        System.err.println("总耗时："+sumTime+"ms,平均处理时长："+sumTime/sum+"ms,错误数量："+errNum+"，正确识别率："+c+"%");
        return resultList;
    }
}
